﻿using CoreApi;
using CoreApi.Meta;
using System;
using System.Web.Http;
using System.Configuration;
using CoreService.Models;
using System.Linq;

namespace CoreService.Controllers
{
    public class DAQController : BaseController
    {
        private IDataCollect _dataCollect;        

        public DAQController(IDataCollect dataCollect)
        {
            this._dataCollect = dataCollect;
            _appKeys = ConfigurationManager.AppSettings["daqKey"].Split(';');
        }

        [HttpPost]
        public IHttpActionResult BloodPressureMeasureDataCollect([FromBody]BloodPressureMeasureDataRequest data)
        {
            try
            {
                ReturnValue rv1=CheckAppKey(data.AppKey);
                if (!rv1.Passed) return Ok < ReturnValue>(rv1);
                ReturnValue rv = this._dataCollect.CollectBloodPressureMeasureData(data);
                return Ok < ReturnValue>(rv);
            }
            catch(Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult GlycemicMeasureDataCollect([FromBody]GlycemicMeasureDataRequest data)
        {
            try
            {
                ReturnValue rv1 = CheckAppKey(data.AppKey);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._dataCollect.CollectGlycemicMeasureData(data);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult SmokeAlarmSignalCollect([FromBody]AlarmSignalRequest data)
        {
            try
            {
                ReturnValue rv1 = CheckAppKey(data.AppKey);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._dataCollect.CollectSmokeAlarmSignal(data);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult GasAlarmSignalCollect([FromBody]AlarmSignalRequest data)
        {
            try
            {
                ReturnValue rv1 = CheckAppKey(data.AppKey);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._dataCollect.CollectGasAlarmSignal(data);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

    }
}
